package ttOrder.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import ttOrder.model.po.FoodType;
import ttOrder.service.FoodTypeServiceImpl;
import ttOrder.util.CommonMessageResultVO;
@RestController
@RequestMapping("/ttOrder")
public class foodtypeController {
	@Resource
	private FoodTypeServiceImpl foodtypeservice;
	
	
	@RequestMapping("/foodtype")
	public List<FoodType> foodtypes(Model model){
		List<FoodType> foodtypes = foodtypeservice.getAll();
		model.addAttribute("foodtypes", foodtypes);
		return foodtypes;
	}
	
	@RequestMapping(value = "/addFoodtype", method = RequestMethod.POST)
	public CommonMessageResultVO addFoodtype(Model model,FoodType foodtypes){
		CommonMessageResultVO vo = new CommonMessageResultVO();
		try{
			foodtypeservice.insert(foodtypes);
			
		}catch(Exception e){
			e.printStackTrace();
		}
		vo.setSuccess(true);
		return vo;
	}
	
	

	@RequestMapping(value = "/editFoodtype", method = RequestMethod.POST)
	public CommonMessageResultVO editFoodtype(Model model,FoodType foodtypes){
		CommonMessageResultVO vo = new CommonMessageResultVO();
		try{
			foodtypeservice.update(foodtypes);
			
		}catch(Exception e){
			e.printStackTrace();
		}
		vo.setSuccess(true);
		return vo;
	}
	
	
	@RequestMapping(value = "/delFoodtype", method = RequestMethod.POST)
	public CommonMessageResultVO delFood(Model model,Integer[] ids){
		CommonMessageResultVO vo = new CommonMessageResultVO();
		try{
			for(int i = 0 ; i<ids.length ; i++){
				FoodType foodtypes = new FoodType();
				foodtypes.setId(ids[i]);
				foodtypeservice.deleteByKey(foodtypes);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		vo.setSuccess(true);
		return vo;
	}
}